#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

const int kMaxN = 1010;

struct Recode {
  int v, t, end;
} Bessie[kMaxN], Elsie[kMaxN];
vector<int> points;

int main() {
  freopen("cowrace.in", "r", stdin);
  freopen("cowrace.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, pos;

  cin >> n >> m;

  pos = 0;
  points.emplace_back(pos);
  for (int i = 0; i < n; i++) {
    cin >> Bessie[i].v >> Bessie[i].t;
    if (Bessie[i].t == 0) {
      n--, i--;
      continue;
    }
    pos += Bessie[i].t;
    Bessie[i].end = pos;
    points.emplace_back(pos);
  }
  pos = 0;
  for (int i = 0; i < m; i++) {
    cin >> Elsie[i].v >> Elsie[i].t;
    if (Elsie[i].t == 0) {
      m--, i--;
      continue;
    }
    pos += Elsie[i].t;
    Elsie[i].end = pos;
    points.emplace_back(pos);
  }
  sort(points.begin(), points.end());
  points.resize(unique(points.begin(), points.end()) - points.begin());

  int ans = 0;
  int bpos = 0, epos = 0;
  int lead = 0;

  for (int p = 0, q = 0, i = 1; p < n && q < m && i < points.size(); i++) {
    int dt = points[i] - points[i - 1];
    bpos += dt * Bessie[p].v;
    epos += dt * Elsie[q].v;

    if (points[i] == Bessie[p].end) {
      p++;
    }
    if (points[i] == Elsie[q].end) {
      q++;
    }
    int old_lead = lead;

    if (bpos > epos) {
      lead = -1;
    } else if (bpos < epos) {
      lead = 1;
    }
    if (old_lead * lead < 0) {
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}